package com.dukk.espark.apps;


import com.alibaba.fastjson.JSONObject;
import com.dukk.espark.core.Engine;
import com.dukk.espark.core.SparkBase;
import org.apache.sedona.core.formatMapper.GeoJsonReader;
import org.apache.sedona.core.spatialRDD.SpatialRDD;
import org.apache.sedona.sql.utils.Adapter;
import org.apache.sedona.viz.core.ImageGenerator;
import org.apache.sedona.viz.core.ImageSerializableWrapper;
import org.apache.spark.sql.Dataset;
import org.apache.spark.sql.Row;
import org.locationtech.jts.geom.Geometry;


@Engine(name = "GeoJsonApp")
public class GeoJsonApp extends SparkBase {

    @Override
    public void doAi(JSONObject params) {
        Dataset<Row> jsonDataset = sparkSession.read().json(configKit.getEsparkFilePath());
        jsonDataset.printSchema();
        jsonDataset.show();

        SpatialRDD<Geometry> geometrySpatialRDD = GeoJsonReader.readToGeometryRDD(javaSparkContext, "F:\\projects\\gitee\\easy-spark\\src\\main\\resources\\data\\geojson.json");
        Dataset<Row> cityTableDataset =  Adapter.toDf(geometrySpatialRDD, sparkSession);
        cityTableDataset.createOrReplaceTempView("cityTable");
        cityTableDataset.show();


    }
}
